package com.qctpos.crm.openapi.config;

import com.qctpos.crm.common.Interceptor.AuthenticationInterceptor;
import com.qctpos.crm.common.Interceptor.ResponseResultInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 拦截所有请求
        registry.addInterceptor(responseResultInterceptor()).addPathPatterns("/**")
                .excludePathPatterns("/","/swagger","/login")
                /*静态资源的位置*/
                .excludePathPatterns("/static/**").excludePathPatterns("classpath:/static/")
                .excludePathPatterns("/templates/**").excludePathPatterns("classpath:/templates/")
                 /*放行swagger*/
                .excludePathPatterns("/swagger-ui/**")
                .excludePathPatterns("classpath:/META-INF/resources/")
                .excludePathPatterns("/webjars/**")
                .excludePathPatterns("classpath:/META-INF/resources/webjars/");//对应的不拦截的请求;

        //registry.addInterceptor(authenticationInterceptor()).addPathPatterns("/**");
        // 拦截所有请求，通过判断是否有 @LoginRequired 注解 决定是否需要登录
    }

    @Bean
    public ResponseResultInterceptor responseResultInterceptor() {
        return new ResponseResultInterceptor();
    }
    //@Bean
    //public AuthenticationInterceptor authenticationInterceptor() {
        //return new AuthenticationInterceptor();
    //}
}